// 引入封装的axios
import serve from "@/utils/serve";

// 定义注册的参数类型
interface paramsData {
  phone:string,
  password:string,
  code:string
}
// 定义获取验证码和注册成功的返回值类型
export interface resData {
  code:number,
  data:string,
  message:string,
  ok:boolean
}

// 定义登录接口的参数类型
export interface logonData {
  phone:string,
  password:string,
}
// 定义登录接口的返回值data类型
interface dataData {
  name:string,
  nickName:string
  token:string,
  userId:number
}
// 定义登录成功的返回值类型
export type loginResData = {
  code: string
  message: string
  data: dataData
  ok: boolean 
}

// 定义获取用户信息的返回值类型
export interface UserInfoData {
  "routes": string[],
  "buttons": string[],
  "roles": string[],
  "name": string,
  "avatar": string
}

// 定义获取用户信息的返回值类型
export type userInforesDate = {
  code:string,
  data:userInfoData,
  message:string
  ok:boolean
}
interface userInfoData {
  birthday:null,
  createTime:string,
  email:null,
  gender:string,
  headImg:string,
  id:number,
  nickName:string,
  openId:null,
  operateTime:string,
  passwd:string,
  phoneNum:string,
  status:number,
  userLevel:string
}

export default {
  /**
   * @description 获取验证码
   * @url /api/user/passport/sendCode/{phone}
   * @param phone 手机号
   * @returns Promise<resData>
   */
  reqSendCode(phone:string){
    return serve.get<any,resData>(`/api/user/passport/sendCode/${phone}`)
  },

  /**
   * @description 用户注册
   * @url /api/user/passport/register
   * @param params 请求体参 {phone,password,code}
   * @returns Promise<resData>
   */
  reqRegister(params:paramsData){
    return serve.post<any,resData>('/api/user/passport/register', params)
  },

  /**
   * @description 登录
   * @url /api/user/passport/login
   * @param logondata 请求体参 {phone,password}
   * @returns Promise<loginResData>
   */
  userLogin(logondata:logonData){
    return serve.post<any,loginResData>('/api/user/passport/login',logondata)
  },


  /**
   * @description 获取用户信息
   * @url /api/user/passport/auth/getUserInfo
   */
  getUserInfo(){
    return serve.get<any,userInforesDate>('/api/user/passport/auth/getUserInfo')
  },

  /**
   * @description 退出登录
   * @url /api/user/passport/logout
   * @returns Promise<null>
   */
  userLogout(){
    return serve.post<any,null>('/api/user/passport/logout')
  }
}